package com.ljkj.cordial.chat.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ljkj.cordial.chat.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 加载
 */
public class NetProgressBarDialog extends Dialog {
    @BindView(R.id.affairListProgressBar)
    ProgressBar affairListProgressBar;
    @BindView(R.id.tv_des)
    TextView tvDes;
    private Unbinder unbinder;

    public NetProgressBarDialog(@NonNull Context context) {
        super(context, com.nic.view.R.style.dialog_no_bg_alpha);
        setContentView(R.layout.dialog_net_progress);
        unbinder = ButterKnife.bind(this);
        setCancelable(false);
        setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    dismiss();
                }
                return false;
            }
        });
    }

    public NetProgressBarDialog(@NonNull Context context, boolean flag) {
        super(context, com.nic.view.R.style.dialog_no_bg_alpha);
        setContentView(R.layout.dialog_net_progress);
        unbinder = ButterKnife.bind(this);
        setCancelable(flag);
        setCanceledOnTouchOutside(flag);
    }

    public NetProgressBarDialog setCancel(boolean flag) {
        setCancelable(flag);
        return this;
    }

    public NetProgressBarDialog setDes(String desc) {
        tvDes.setText(desc);
        return this;
    }

    @Override
    public void dismiss() {
        super.dismiss();
//        unbinder.unbind();
    }

}
